// ScriptDefinitions are created by the ScriptCompiler
package DramScript
{
	public class ScriptDefinition
	{
 		import utils.Trace;
		public  var _statementDefArr:Array = new Array(
				// DramActor. 
				// newactor creates an Actor. All actors are swf's for now
				// NEWACTOR ACTORNAME [SWFNAME] [DEFAULTSYMBOLNAME]
				// After NEWACTOR ACTORNAME is available for use in other commands
				new Array("preprocess","newactor","string","[String]=param0","[String]=param0"), 				
				// Enter ActorName  x y z
				// Enter Darwin1 100 200 1
				// Enter Tree1  -  if thingType == actorName
				new Array("game","Enter","ACTORNAME","[Number]=-1000", "[Number]=-1000", "[Number]=0"), 				
				new Array("game","exit","ACTORNAME"),
				// Name a new Place. Once a Place is named, its PLACENAME can be used in other commands
				// NEWPLACE PLACENAME BACKGROUNDNAME
				// NEWPLACE GODZ_CLOSET CLOSET.JPG
				new Array("preprocess","newplace","string","string"),
				// load background graphic. BACKGROUND entrance/cave_back.jpg 
				// BACKGROUND filename x y depth
				new Array("game","background","placename", "string","[Number]=0","[Number]=0","[Number]=-1"),
				// GOPLACE PLACENAME
				// goplace GODZ_CLOSET
				new Array("game","goplace","placename"),
				// LAYER PLACENAME GRAPHICNAME x=0 y=0 depth = -1
				// layer GODZ_CLOSET shelf.gif
				new Array("game","layer","placename","string","[Number]=0","[Number]=0","[Number]=-1"),
				// HOTSPOT_CALLSCRIPT PLACENAME GRAPHICNAME SCRIPTNAME x=0 y=0 depth = -1
				// HOTSPOT_CALLSCRIPT GODZ_CLOSET shelf.gif newplace.dram
				new Array("game","hotspot_callscript","placename","string","string","[Number]=0","[Number]=0","[Number]=-1"),



				// The following commands can either be scripted "Command ACTORNAME" or "ACTORNAME Command"
				// Move ActorName, Relative x y [z=0] [seconds=4]
				new Array("actor","Move","ACTORNAME","Number","Number","[Number]=0","[Number]=5"), 
				// Moveto, ActorName, Absolute x y [z=0] [seconds=4]
				new Array("actor","MoveTo","ACTORNAME","Number","Number","[Number]=0","[Number]=4"),  // 
				// Actor Says "Hello dere!"
				new Array("actor","Says","ACTORNAME","QuoteString"),
				// Animate Actor AnimationName, repeatCount, optional param
				// optional param example: FSM Animate Spell 1 "u suk"
				new Array("actor","Animate","ACTORNAME","String","[Number]=1","[quotestring]=\"\""), 
				// Wait - Until animation, move, or rotate ends for all named actors
				new Array("actor","Wait","ACTORNAME","..."),
				// Scale, ACTORNAME, %scale, seconds
				new Array("actor","Scale","ACTORNAME","number","[Number]=0"),
				// ScaleTo, ACTORNAME, %scale, seconds
				new Array("actor","ScaleTo","ACTORNAME","number","[Number]=0"),
				// StretchTo. ACTORNAME, scaleX, scaleY, seconds
				new Array("actor","StretchTo","ACTORNAME","number","number","[Number]=0"),
				// Stretch. ACTORNAME, scaleX, scaleY, seconds
				new Array("actor","Stretch","ACTORNAME","number","number","[Number]=0"),
				// alpha, actor, alpha%, seconds
				new Array("actor","alpha","ACTORNAME","number","[Number]=0"),
				// Rotate, ACTORNAME, Relative Degrees, Seconds
				new Array("actor","Rotate","ACTORNAME","Number","[Number]=0"),
				// RotateTo, ACTORNAME, Asolute Degrees, "cw" or "ccw" , Increments
				new Array("actor","RotateTo","ACTORNAME","Number","[cw/ccw]=cw","[Number]=0"),
				
				// Stop/restart processing commands
				new Array("game","pause","ACTORNAME"),
				new Array("game","unpause","ACTORNAME"),
				
				// Mark all actors as offscreen
				new Array("game","sys_changescene"),
				
				// runscript is a goto, callscript is a gosub
				new Array("game","runscript","string"),
				new Array("game","callscript","string"),
				// endscript stops the current script.
				// if the boolean parameter is true it moves all actors offstage
				new Array("game","endscript","[boolean]=true"),
	
				// Control flow commands
				new Array("ui","IfChoose","QuoteString","[QuoteString]", "[QuoteString]","[QuoteString]","[QuoteString]","[QuoteString]"), // Must have 1, may have 6 choice
				new Array("script","ElseIf"),
				new Array("script","EndIf"),
				new Array("script","ifRandom","integer"),
				new Array("script","Loop","[integer]=1000000000"),
				new Array("script","EndLoop"),				
				
				new Array("script","trace","quotestring"),
				
				// sound
				new Array("sound","soundfx","quotestring"),
				new Array("sound","music","quotestring"),
				new Array("sound","musicvolume","number"),
				new Array("sound","soundfxvolume","number"),
				// Hide/show volume sliders
				new Array("sound","showcontrol"),
				new Array("sound","hidecontrol"),
				// WaitTime #miliseconds
				new Array("game","WaitTime","Number"),

				// Unimplemented
				// Variable commands
				new Array("uzer","VarNumber","VarNumberInstance","[Number]"), 
				new Array("uzer","VarString","string","quotestring"), 
				// quotestring in varboolean to encourage long bool names
				// "Finished Hairy Noodle Quest", "Knows GOD is Fred."
				new Array("uzer","VarBoolean","quotestring","boolean"), 
				// ??? new Array("uzer","SetVar","Var","Number"),
				new Array("uzer","AddVarNumber","VarNumberInstance","Number"),
				new Array("uzer","IfVarNumberEqual","VarNumberInstance","Number"),
				new Array("uzer","IfVarNumberMore","VarNumberInstance","Number"),
				new Array("uzer","IfVarNumberLess","VarNumberInstance","Number"),
				new Array("uzer","ifVarStringEqual","varstringinstance","quotestring"),
				new Array("uzer","ifVarBooleanEqual","varbooleaninstance","boolean"),
					// Game state
				new Array("uzer","ifplace","quotestring"),
				new Array("uzer","ifownitem","quotestring"), 
				
				new Array("game","ifhotspot","quotestring")
			
		)	; // Array of statement definitions		// Make this verify the script definition
		// Define non-standard types
		// _customTypeArr[n][0] is the type name used in the statement definitions
		// _customTypeArr[n][1-last] are legal example of that type
		public var _customTypeArr:Array = new Array(
			new Array("spin","cw","ccw")
		);
		
		public function ScriptDefinition():void {
		}
		// Currently all commands that start with "if" are branchers
		public static function isBranchingCommand( command:String ):Boolean {
			var result:Boolean = false;
			if( command.indexOf( "if" ) == 0){
				result = true;
			}
			return result;
		}
		// handed a command returns its target
		public function getCommandTarget( command:String ):String {
			var i:int;
			var foundIt:Boolean = false;
			for( i = 0; i < this._statementDefArr.length ; i++ ){
				if( command == this._statementDefArr[i][1] ){
					foundIt = true;
					break;
				}
			}
			if( !foundIt ){
				Trace.throwError("Can't find target for command: "+command);
			}
			return this._statementDefArr[i][0];;
		}

		
	}
}